<?php

session_start();

function listImages() {
	define('IMAGEPATH', 'images/');

	if (is_dir(IMAGEPATH)){
		$handle = opendir(IMAGEPATH);
	} else{
		echo 'No image directory';
	}

	$directoryfiles = array();
	while (($file = readdir($handle))) {
		if (($file == '.')||($file == '..')) {
			continue;
		}
		$newfile = str_replace(' ', '_', $file);
		rename(IMAGEPATH . $file, IMAGEPATH . $newfile);
		$directoryfiles[] = $newfile;
	}

	foreach($directoryfiles as $directoryfile) {
		if(strpos($directoryfile, '.jpg') || strpos($directoryfile, '.png') || strpos($directoryfile, '.jpeg') || strpos($directoryfile, '.gif')) {
			echo '<li><a href="' . IMAGEPATH . $directoryfile . '" rel="lightbox[varer]">'.$directoryfile.' </a></li>';
		}
	}
	closedir($handle);
}

?>


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<script src="js/jquery-1.7.2.min.js"></script>
	<script src="js/lightbox.js"></script>
	<link href="css/lightbox.css" rel="stylesheet" />
	<title>Liste over billeder</title>
	<style type="text/css">
		li{
			font-family:"Times New Roman", Times, serif;
			font-size:14px;
		}
	</style>
</head>
<body>
	<div id="mainWraper">
	<h2>Liste over billeder</h2>
		<ol><?php listImages(); ?></ol>
	</div>
</body>
</html>



